<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>


<script>

    var frequencySort = function (nums) {
        let dict = {}
        for (let i = 0; i < nums.length; i++) {
            let key = nums[i]
            if (dict[key] === undefined) {
                dict[key] = 1;
            } else {
                dict[key] = dict[key] + 1;
            }
        }
        let res = nums.sort((a, b) => {
            if (dict[a] !== dict[b]) {
                return dict[a] - dict[b]
            } else {
                return b - a;
            }
        })
        return res;
    };
</script>